﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using SDi.Login.Model;
using System.Web;

namespace SDi.Login
{
    public class SDiAllowedPage : Page
    {
        protected List<string> RequiredCapabilities = new List<string>();

        public void Page_Init(object sender, EventArgs e)
        {
            if (HttpContext.Current.ApplicationInstance as SDiGlobal != null)
            {
                var capabilitiesCodes = (from u in SDiGlobal.AuthenticatedUser.Capabilities
                                         where RequiredCapabilities.Contains(u.Code)
                                         select u.Code).ToList();

                if (capabilitiesCodes.Count < 1)
                {
                    SDiGlobal.RedirectToHomePage("You don't have permissions for this page!");
                }

            }
            else
            {
                SDiGlobal.RedirectToHomePage("Error in application!");
            }
        }
    }
}
